import { convertToYears } from "@/utils/date";

export function sortPmsSkuPriceByAge(pmsSkuPrices) {
  pmsSkuPrices.sort((a, b) => {
    const startAgeAInYears = convertToYears(a.startPurchaseAge, a.startUnit);
    const startAgeBInYears = convertToYears(b.startPurchaseAge, b.startUnit);
    const span = startAgeAInYears - startAgeBInYears;
    if (span === 0) {
      return a.paymentMethod - b.paymentMethod;
    }
    return span;
  });
  return pmsSkuPrices;
}
